import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { MdlSnackbarService, MdlDialogService } from '@angular-mdl/core';
import { TreeNode, DynamicDialogRef, DynamicDialogConfig } from 'primeng/primeng';
@Component({
  templateUrl: './finish.component.html',
  styleUrls: ['./finish.component.scss'],
  providers: []
})
export class FinishComponent implements OnInit {
  systemUrl: string;
  loading = true;
  recId: number;
  actId: number;
  submit: boolean = false;// 防止重复提交
  opinion: string = "";
  //选中案由参数
  selectedRecords: any = {};
  constructor(
    private http: HttpClient,
    public ref: DynamicDialogRef,
    public config: DynamicDialogConfig,
    public mdlSnackbarService: MdlSnackbarService
  ) {
    this.systemUrl = config.data.systemUrl;
    this.selectedRecords = config.data.selectedRecords;
  }

  ngOnInit() {
    this.recId = this.selectedRecords[0]['rec_id'];
    this.actId = this.selectedRecords[0]['act_id'];
  }

  /** 办结 */
  save() {
    this.submit = true;
    this.http.post('/'+this.systemUrl+'/api/workflow/rollback',
      {
        'recId': this.selectedRecords[0]['rec_id'],
        'actId': this.selectedRecords[0]['act_id'],
        'opinion': this.opinion
      }).subscribe(data => {
        this.ref.close(data);
        this.mdlSnackbarService.showToast('办结成功！')
      });

  }

  /** 取消 */
  cancel() {
    this.ref.close();
  }
}
